/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.insa.glaizot;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 *
 * @author 4glaitan
 */
public class ExempleFichier {

    public static void ecritChaine(File f , String texte) throws IOException {

        FileWriter fout = new FileWriter(f);
        fout.append(texte);
        fout.close();

    }

    public static void testEcrire() {
        try {
            File ou = new File("toto.txt");
            String quoi = "Bonjour\ntoto\ntu vas bien ?";
            ecritChaine(ou, quoi);
        } catch (IOException ex) {
            System.out.println("C'EST TOUT CASSE !!! : " + ex);;
        }
    }

    public static String litFichier(File f) throws IOException {

        FileReader fin = new FileReader(f);
        BufferedReader bin = new BufferedReader(fin);
        String res = "";
        String line = bin.readLine();
        while (line != null) {
            res = res + line + "\n";
            line = bin.readLine();
        }
        bin.close();
        return res;
    }

    public static void testLire() {
        try {
            File ou = new File("toto.txt");
            String lu = litFichier(ou);
            System.out.println("fichier lu : \n" + lu);
        } catch (IOException ex) {
            System.out.println("C'EST TOUT CASSE !!! : " + ex);;
        }
    }

    public static void main(String[] args) {

//        testEcrire();
//        testLire();

    }

}
